<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>注册</title>
    <link href="../css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<!--登录名: <input type="text" placeholder="输入账号" id="logname">-->
<!--密码:<input type="password" placeholder="请输入密码" id="pwd">-->
<!--昵称:<input type="text" id="nickname">-->

<div class="container">
    <form class="form-horizontal" style="width: 400px; margin: 100px auto" action="/loginsubmit" method="post">
        <div class="form-group">
            <label for="logname" class="col-sm-2 control-label">账号</label>
            <div class="col-sm-10">
                <input type="text" class="form-control" name="username" id="logname" placeholder="账号">
            </div>
        </div>
        <div class="form-group">
            <label for="pwd" class="col-sm-2 control-label">密码</label>
            <div class="col-sm-10">
                <input type="password" class="form-control" name="password" id="pwd" placeholder="密码">
            </div>
        </div>
        <div class="form-group">
            <label for="repwd" class="col-sm-2 control-label">确认密码</label>
            <div class="col-sm-10">
                <input type="password" class="form-control" name="password" id="repwd" placeholder="再次输入密码">
            </div>
        </div>
        <div class="form-group">
            <label for="nickname" class="col-sm-2 control-label">昵称</label>
            <div class="col-sm-10">
                <input type="text" class="form-control" name="nickname" id="nickname" placeholder="昵称">
            </div>
        </div>

        <div class="form-group">
            <div class="col-sm-offset-2 col-sm-10">
                <button type="button" class="btn btn-default" id="sub">提交</button>
                <button type="button" class="btn btn-default" id="return">返回</button>
            </div>
        </div>
    </form>
</div>


<script src="../js/jquery-3.2.1.js"></script>
<script>
    $("#sub").click(function () {
        var pwd = $("#pwd").val();
        var repwd = $("#repwd").val();
        if (pwd === repwd) {
            $.ajax({
                url: "/register",
                type: "post",
                data: {
                    username: $("#logname").val(),
                    password: $("#pwd").val(),
                    name: $("#nickname").val()
                },
                success: function (result) {
                    alert("注册成功");
                    window.location.href = "/"
                },
                error: function () {
                    alert("错误")
                }
            })
        }else {
            alert("两次输入密码不一致")
        }
    });
    $("#return").click(function () {
        window.location.href = "/login"
    });
</script>
</body>
</html>